//
//  BrokerOfStoreView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/6/3.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

//#define ImgeForwardUrl2 @"http://files.wgfcdn.com/"

#import "BrokerOfStoreView.h"
#import "StringTool.h"
#import "UIView+circular.h"
#import "API.h"

#import "UIImageView+WebCache.h"

@interface BrokerOfStoreView()

@property (weak, nonatomic) IBOutlet UIButton *selecteStatuBtn;

@property (weak, nonatomic) IBOutlet UIImageView *headerImg;

@property (weak, nonatomic) IBOutlet UILabel *brokerNamelab;
@property (weak, nonatomic) IBOutlet UILabel *phonelab;

@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UIView *rightView;
@property (nonatomic,strong) NSLayoutConstraint* conLay;
@property (weak, nonatomic) IBOutlet UILabel *tiplab;

@end


@implementation BrokerOfStoreView

+(instancetype)createView
{
    BrokerOfStoreView *view = [[[NSBundle mainBundle]loadNibNamed:@"BrokerOfStoreView" owner:nil options:nil]lastObject];
    
    for (NSLayoutConstraint *conLayout in view.constraints) {
        
        if (conLayout.firstItem==view.headerImg&&conLayout.firstAttribute ==NSLayoutAttributeLeading) {
            view.conLay = conLayout;
            break;
        }
    }

    [view.headerImg imgViewToCircular:view.headerImg];
    
    return view;
}

-(void)setModel:(BorkerCellModel *)model
{
//    [API imgUrlMake:model.brokerAvatar];
    NSString *url =   [API videoUrlMake:model.brokerAvatar];;
    if (![StringTool isBlankString:model.brokerAvatar]) {
        
        [self.headerImg sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"user_portiart"]];
    }else{
         [self.headerImg sd_setImageWithURL:nil placeholderImage:[UIImage imageNamed:@"user_portiart"]];
    }
    
   
    if (![StringTool isBlankString:model.brokerName]) {
        self.brokerNamelab.text = model.brokerName;
    }
    if (![StringTool isBlankString:model.brokerMobile]) {
        self.phonelab.text = model.brokerMobile;
    }
    if (![StringTool isBlankString:model.brokerages]) {
        self.moneyLab.text = model.brokerages;
    }
    self.selecteStatuBtn.highlighted = model.isSelected;
    self.tiplab.hidden = model.status == 0?YES:NO;
}



-(void)hideRightView:(Boolean)hide{

    [self.rightView setHidden:hide];
}

-(void)setIsEditMode:(Boolean)isEditMode
{
    [self.rightView setHidden:isEditMode];
    
    self.conLay.constant = isEditMode?40:8;
    
    [self layoutIfNeeded];
}

@end
